/*
 * Copyright (c) 2013 by Chances.
 * $CVSHeader$
 * $Author$
 * $Date$
 * $Revision$
 */
package chances.epg.search.searcher;

import java.util.ArrayList;
import java.util.List;

import chances.epg.commons.utils.JSONUtils;


/**
 * Class comments.
 *
 * @author <a href="mailto:libf@chances.com.cn">libf</a>
 */
public class SearchResult {
    private int totalCount = 0;
    private int totalPage = 0;
    private int pageSize = 10;
    
    public SearchResult() {
    }
    
    public SearchResult(int pageSize) {
        this.pageSize = pageSize;
    }
    
    private List<Object> result;
    /**
     * @return the totalCount
     */
    public int getTotalCount() {
        return totalCount;
    }
    /**
     * @param totalCount the totalCount to set
     */
    public void setTotalCount(int totalCount) {
        this.totalCount = totalCount;
    }
    
    /**
     * @return the totalPage
     */
    public int getTotalPage() {
        this.totalPage = (int) this.totalCount/ pageSize;
        int lastPageSize = (int) this.totalCount % this.pageSize;
        if(lastPageSize != 0){
            this.totalPage ++;
        }
        return totalPage;
    }
    
    /**
     * @return the result
     */
    public List<Object> getResult() {
        if(this.result == null){
            this.result = new ArrayList<Object>();
        }
        
        return result;
    }
    /**
     * @param result the result to set
     */
    public void setResult(List<Object> result) {
        this.result = result;
    }
    
    /**
     * @return the pageSize
     */
    public int getPageSize() {
        return pageSize;
    }
    /**
     * @param pageSize the pageSize to set
     */
    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }
    
    
    public static void main(String[] args) {
        SearchResult result = new SearchResult();
        result.setTotalCount(8);
        result.setPageSize(10);
        
        List<String> items = new ArrayList<String>();
        items.add("{a:dd}");
        items.add("{a:bb}");
        items.add("{a:cc}");
        
        String JSONResult = new StringBuffer().append("{'totalCount':'")
        .append(result.getTotalCount())
        .append("','totalPage':'")
        .append(result.getTotalPage())
        .append("','JSONArray':")
        .append(JSONUtils.fromObject(items))
        .append("}").toString();
        
        System.out.println(JSONResult);
    }
}
